package compositeExpression;

import java.util.LinkedList;
import java.util.List;
import compositeExpression_Term.MinusTerm;
import compositeExpression_Term.PlusTerm;
import visitor.Visitor;
import exceptions.IllegalContextException;

public class Expr extends NumberExpression {
	
	private List<Expression> term;
	
	public Expr(Expression term) {

        if (term == null) {

            throw new NullPointerException();
        }

        this.term = new LinkedList();
        this.term.add(term);
    }

	@Override
	public void toAssess(String p) throws IllegalContextException {
		for (Expression te : term) {

            te.toAssess(p);
        }
	}
	
	public List<Expression> getState() {

        return term;
    }


	@Override
	public String toString() {
		 StringBuilder sb = new StringBuilder();

	        for (Expression tr : term) {

	            if (tr instanceof PlusTerm) {

	                sb.append(" + ");
	            } else if (tr instanceof MinusTerm) {

	                sb.append(" - ");
	            }

	            sb.append(tr);
	        }
	        return sb.toString();
	    }
	

	@Override
    public void accept(Visitor v) {
        v.visit(this);
    }

	@Override
	public void add(Expression term) {
		if (term == null) {

            throw new NullPointerException();
        }

        this.term.add(term);		
	}

}
